package co.fitstart.admin.web.controller.course;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import co.fitstart.admin.service.BasicInformationService;
import co.fitstart.admin.service.CourseRoundService;
import co.fitstart.admin.service.ResultReportService;
import co.fitstart.admin.web.interceptor.MenuSetting;
import co.fitstart.entity.course.round.CourseRound;
import co.fitstart.entity.course.round.CourseRoundResult;
import co.fitstart.entity.courseware.assessment.BasicData;
import co.fitstart.entity.user.bwh.BwhRecord;

/**
 * 成果报告
 * @author haiyan_xiao
 *
 */
@Controller
@RequestMapping("/individual-rounds/{courseRoundId}/result-report")
@MenuSetting("menu-course")
public class ResultReportController {
	
	private static final Logger logger = LoggerFactory.getLogger(ResultReportController.class);
    @Autowired
    private CourseRoundService courseRoundService;
    
    @Autowired
    private ResultReportService resultReportService;
    
    @Autowired
    private BasicInformationService basicInformationService;
    
    /**
     * 成果报告展示页
     * @param courseRoundId
     * @return
     */
    @RequestMapping(value = "", method = RequestMethod.GET)
    @MenuSetting("submenu-individual-course-arrange")
    public ModelAndView basicInformationview(@PathVariable("courseRoundId") Long courseRoundId) {
        
        ModelAndView modelAndView = new ModelAndView("course/individual/individual-round-result-report-view");
        
        CourseRound courseRound = courseRoundService.loadCourseRound(courseRoundId);
        modelAndView.addObject("courseRound", courseRound);
        
        List<BwhRecord> bwhRecords = resultReportService.listBwhRecord(courseRound);
        modelAndView.addObject("bwhRecords", bwhRecords);
        
        BasicData basicData = basicInformationService.loadBasicData(courseRound);
        modelAndView.addObject("basicData", basicData);
        
        CourseRoundResult resultReport = resultReportService.loadResultReport(courseRound);
        modelAndView.addObject("resultReport", resultReport);
        
        logger.info("# ResultReportController basicInformationview() courseRoundId [{}] resultReport [{}]",courseRound.getId(),resultReport);
        
        CourseRoundResult result = courseRoundService.loadCourseRoundResult(courseRound);
        modelAndView.addObject("result", result);
        
        return modelAndView;
    }
}
